//
//  ViewController.m
//  06-UINavigationController
//
//  Created by mafeng on 16/7/21.
//  Copyright © 2016年 mafeng. All rights reserved.
//

#import "ViewController.h"
#import "PushViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    // 设置navigationbar 的属性
    // 1. title 标题
    self.title = @"标题";  // 这里的title被冲掉了
    self.navigationItem.title = @"XXX";
    // 2. titleview 标题视图
    // 标题视图, 修改x, y对视图本身没有影响
    UISegmentedControl *seg = [[UISegmentedControl alloc] initWithItems:@[@"晃晃", @"马峰"]];
    seg.frame = CGRectMake(0, 0, 250, 44);
    self.navigationItem.titleView = seg;
    // 3. leftBarButtonItem
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(back:)];
    // 4. rightBarButtonItem
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(nibBundle)];
    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPlay target:self action:@selector(nibBundle)];
    // 5. leftBarButtonItems
    UIBarButtonItem *barButtonItemTitle = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(back:)];
    UIBarButtonItem *barButtonItemTitle1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(back:)];
    self.navigationItem.leftBarButtonItems = @[barButtonItemTitle, barButtonItemTitle1];
    // 6. leftBarButtonItems
    // leftBarButtonItems 数组中放一到两个为优
    // 7. 隐藏 下面两个等效
    self.navigationController.navigationBarHidden = NO;
    self.navigationController.navigationBar.hidden = NO;
    // 8. barStyle 背景样式, 默认default
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    // 9. navigationBar的背景颜色
   // self.navigationController.navigationBar.backgroundColor = [UIColor redColor];
    // 10. barTintColor Bar的颜色
    self.navigationController.navigationBar.barTintColor = [UIColor redColor];
    // 11. Bar上元素的颜色
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    // 12. translucent 管理半透明效果, YES为开启, NO为关闭
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.backgroundColor = [UIColor yellowColor];
    [button addTarget:self action:@selector(next) forControlEvents:UIControlEventTouchUpInside];
    button.frame = CGRectMake(0, 0, 200, 200);
    [self.view addSubview:button];
    // 设置为yes时, self.view坐标系从原点开始
    // 设置为no时, self.view坐标系从navigationBar开始
    // 默认为yes
    self.navigationController.navigationBar.translucent = YES;
    // 13. 改变坐标效果, 与translucent为NO效果一样
    //self.edgesForExtendedLayout = UIRectEdgeNone;
    // 页面跳转相关
    // 1. push 入栈 pushViewController
    // 2. pop 出栈 popViewControllerAnimated
    // 3. viewcontroller 存放navigationgController里所有的视图控制器
    // 4. topViewController 栈顶视图控制器
    // 5. visibleViewController 当前显示的视图控制器
    
    // 将 navigationBar 设置为透明的, 并消除下面的那条分界线
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage = [UIImage new];
    
    
}
- (void)next{
    // 将视图控制器入栈出栈
    [self.navigationController pushViewController:[[PushViewController alloc] init] animated:YES];
}
- (void)back:(UIBarButtonItem *)barButtonItem {
    NSLog(@"返回");
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
